//
//  CActiveAnimation.h
//  Monster_Martial_Arts_Version_0
//
//  Created by chiawei.tseng on 13/1/7.
//
//

#ifndef Monster_Martial_Arts_Version_0_CActiveAnimation_h
#define Monster_Martial_Arts_Version_0_CActiveAnimation_h

#include "AnimationDef.h"
#include "CAnimation.h"
#include "CMemberCallback.h"
#include <vector>
#include <list>

using namespace std;
using namespace MMA;

class CAnimationSystem;
class CAnimationEvent
{
public:
    
    CAnimationEvent();
    ~CAnimationEvent();
    
    void Init(CAnimationSystem*,ANIMATION_ID);
    
    void RunAction();
    
    //void Release();
    
protected:
    
    const char* GetAnimationMapping(ANIMATION_ID);
    
private:
    
    ANIMATION_ID           m_AniamtionID;
    
    CAnimationSystem*      m_AnimationInstance;
};

//===========================================================

class CActiveAnimation;
class CAniamtionEventCallBack : public CCAnimationEventListener
{
public:
    
    CAniamtionEventCallBack();
    ~CAniamtionEventCallBack();
    
    void Init(CActiveAnimation*);
    
    virtual void animationHandler(const char* _aniType, const char* _aniID, const char* _frameID);
    
private:
    
    CActiveAnimation* m_ClassPtr;
    
};

//===========================================================



class CCArmature;
class CAnimationSystem;
class CActiveAnimation
{
public:
    
    CActiveAnimation();
    ~CActiveAnimation();
    
    enum
    {
        INVALID_INDEX =-1,
        START_INDEX = 0 ,
    };
    
    enum CALLBACK_EVENT
    {
        CALLBACK_EVENT_START =0,
        CALLBACK_EVENT_COMPLETE,
        CALLBACK_EVENT_LOOP_COMPLETE,
    };
    
    struct AnimationData
    {
        ACTIVE_ANIMATION_ID m_nActiveAnimationID;
        ACTIVE_ANIMATION_ID m_nNextActiveAnimationID;
        ANIMATION_ID m_AniamtionIDs[ANIMATION_EVENT_MAX];
        int  m_AnimationCount;
        bool m_RunLoop;
    };
    
    struct ACTION_EVENT
    {
        int callBackEvent;
    };
    
    void Init(CAnimationSystem*,AnimationData);
    void EnteringAnimation();
    void RunAnimation(float dt);
    void LeavingAnimation();
    bool isCanChangeActiveAnimation();
    void Release();
    
    void StartAniamtionCallBack();
    void CompleteAnaimationCallBack();
    void LoopCompleteAnimationCallBack();
    
    void RegisterCallBack(CCallBack*);
    
protected:
    
    void onProcessCallBack(CALLBACK_EVENT);
    
    
    vector<CAnimationEvent*> m_AnimationEvents;
    
    list<CCallBack*>        m_CallBackClassSet;
    
    CAniamtionEventCallBack* m_AnimationCallBack;
    
    void CreateAnimationContext();

private:

    int  m_nCurrAnimationIndex;
    int  m_nNextAnimationIndex;
    
    AnimationData        m_AnimationData;
    
    CAnimationSystem*    m_AnimationSys;

};






#endif